﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace NSX07.Admin
{
    public partial class usermanager : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            Button bt = (Button)sender;

            string username = bt.CommandArgument;
            string passworld = bt.CommandName; ;
            
            user.Text = username;
            pass.Text = passworld;


            string par1 = username;
            string par2 = passworld;
            string address = "http://localhost:37915/Service1.asmx";
            string function = "loginNKD";

           

            if (username == "admin")
            {

            }
            else 
            {
                XmlNode _node = (XmlNode)WebserviceInvoker.WSInvoker.CallWebService(address, "Service1", function, new object[] { par1, par2 });
                key.Text = _node.FirstChild.Value.ToString();

                // lấy danh sách sản phẩm sắp hết hàng

                string fucntionC = "checkStock";
                string par1C = key.Text;
                string par2C = username;
                XmlDocument _doc = new XmlDocument();
                XmlNode _nodeC = (XmlNode)WebserviceInvoker.WSInvoker.CallWebService(address, "Service1", fucntionC, new object[] { par1C, par2C });
                _doc.AppendChild(_doc.ImportNode(_nodeC, true));

                XmlDataSource xmlDSP = new XmlDataSource();
                xmlDSP.ID = "xmlDSPID";

                xmlDSP.Data = _doc.InnerXml;
                xmlDSP.XPath = "root/item";

                dtlProductsMinStock.DataSource = xmlDSP;
                dtlProductsMinStock.DataBind();
        }

        }

        // lấy thông tin chi tiết sách
        protected void m_Click(object sender, EventArgs e)
        {
            Button bt = (Button) sender;
            string iKey = key.Text;
            string username = user.Text;
            int id = int.Parse(bt.CommandArgument);

            string address = "http://localhost:37915/Service1.asmx";
            string function = "productDetail";

            XmlDocument _doc = new XmlDocument();
            XmlNode _node = (XmlNode)WebserviceInvoker.WSInvoker.CallWebService(address, "Service1", function, new object[] { iKey, username,  id });
            _doc.AppendChild(_doc.ImportNode(_node, true));

            XmlDataSource xmlDSP = new XmlDataSource();
            xmlDSP.ID = "xmlDSPID" + id;

            xmlDSP.Data = _doc.InnerXml;
            xmlDSP.XPath = "root/item";

            dtlProductDetails.DataSource = xmlDSP;
            dtlProductDetails.DataBind();

        }


    }
}